home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <sys/time.h>
-
- #include "fft.h"
- #include "constant.h"
-
- /*
- * Precision Dependant declarations
- */
-
- #ifdef DOUBLE
-
- typedef double this_type;
-
- #define TOLERANCE DTOLERANCE
- #define THIS_GEN dgen_
- #define THIS_FFTI dfft1di
- #define THIS_FFT dfft1d
- #define THIS_FFTU dfft1du
- #define THIS_SCAL dscal1d
-
- #endif
-
- #ifdef SINGLE
-
- typedef float this_type;
-
- #define TOLERANCE STOLERANCE
- #define THIS_GEN sgen_
- #define THIS_FFTI sfft1di
- #define THIS_FFT sfft1d
- #define THIS_FFTU sfft1du
- #define THIS_SCAL sscal1d
-
- #endif
-
- /* */
-
- void inimat_();
- void GetArguments();
- void get_values();
-
- int min_size, max_size, inc_size, is_parallel, timing;
- this_type *pa, *pSave;
-
- static long z_sec, z_usec;
- static int first_time = 1;
-
- float second()
- {
- struct timeval s_val;
- struct timezone s_z;
- float time;
- long n_sec, n_usec;
- gettimeofday(&s_val, &s_z);
- n_sec = s_val.tv_sec;
- n_usec = s_val.tv_usec;
- if( first_time ) {
- z_sec = n_sec;
- z_usec = n_usec;
- first_time =0;
- }
- time = (float)(n_sec-z_sec) + (float)(n_usec -z_usec) * 1.0E-6;
- return( time );
- }
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- int i, j, k, n_total, is_wrong, size, inc, n_times, n_flops;
- double x, y, t, emax;
- this_type ratio;
-
- /* ******************************************************* */
- GetArguments( argc, argv);
- /* ******************************************************* */
-
- srandom( (123*getpid()) | 0x01);
-
- for( size=min_size ; size <= max_size ; size *= inc_size) {
-
- n_total = ((size+2)*MAX_STRIDE);
- pa = (this_type *)malloc( (n_total + size + FACTOR_SPACE) * sizeof(this_type));
- if( !(pa) ) {
- fprintf( stderr, "Could not allocate ... Exiting\n");
- exit (-1);
- }
-
- fflush(stdout);
-
- printf( "%4d ", size);
-
- n_flops = (int) (5. * (double)(size/2) * (log((double)(size/2))/log(2.)));
- n_times = (int) (MAX_FLOPS / (double)(2*n_flops));
- if(n_times < 1) n_times =1;
- ratio = 1./(double)size;
- /* *******************************************************
- PACKED --- stride 1
- inc = 1;
- n_total = ((size+2)*inc);
- pSave = pa + n_total;
-
- THIS_GEN(pa, &n_total);
- pSave = THIS_FFTI( size, pSave);
-
- t = second();
- for ( i = 0 ; i < n_times ; i++) {
-
- is_wrong = THIS_FFT( -1, size, pa, inc, pSave);
- is_wrong = THIS_FFT( 1, size, pa, inc, pSave);
- THIS_SCAL( size, ratio, pa, inc);
- }
- t = second() - t;
- if( timing)
- x = t / (double)(2*n_times);
- else
- x = (t > 0) ? (((double)(2*n_times) * (double)(n_flops)*1.e-6) / t) : 0.0;
- printf("%6.4e ", x);
- ******************************************************* */
- /* *******************************************************
- ALMOST_PACKED --- stride 1
- ******************************************************* */
- inc = 1;
- n_total = ((size+2)*inc);
- pSave = pa + n_total;
-
- THIS_GEN(pa, &n_total);
- pSave = THIS_FFTI( size, pSave);
-
- t = second();
- for ( i = 0 ; i < n_times ; i++) {
-
- is_wrong = THIS_FFTU( -1, size, pa, inc, pSave);
- is_wrong = THIS_FFTU( 1, size, pa, inc, pSave);
- THIS_SCAL( size, ratio, pa, inc);
- }
- t = second() - t;
- if( timing)
- x = t / (double)(2*n_times);
- else
- x = (t > 0) ? (((double)(2*n_times) * (double)(n_flops)*1.e-6) / t) : 0.0;
- printf("%6.4e ", x);
- /* *******************************************************
- PACKED --- stride > 1
-
- inc = MAX_STRIDE;
- n_total = ((size+2)*inc);
- pSave = pa + n_total;
-
- THIS_GEN(pa, &n_total);
- pSave = THIS_FFTI( size, pSave);
-
- t = second();
- for ( i = 0 ; i < n_times ; i++) {
-
- is_wrong = THIS_FFT( -1, size, pa, inc, pSave);
- is_wrong = THIS_FFT( 1, size, pa, inc, pSave);
- THIS_SCAL( size, ratio, pa, inc);
- }
- t = second() - t;
- if( timing)
- x = t / (double)(2*n_times);
- else
- x = (t > 0) ? (((double)(2*n_times) * (double)(n_flops)*1.e-6) / t) : 0.0;
- printf("%6.4e ", x);
- ******************************************************* */
- /* *******************************************************
- ALMOST_PACKED --- stride > 1
- ******************************************************* */
- inc = MAX_STRIDE;
- n_total = ((size+2)*inc);
- pSave = pa + n_total;
-
- THIS_GEN(pa, &n_total);
- pSave = THIS_FFTI( size, pSave);
-
- t = second();
- for ( i = 0 ; i < n_times ; i++) {
-
- is_wrong = THIS_FFTU( -1, size, pa, inc, pSave);
- is_wrong = THIS_FFTU( 1, size, pa, inc, pSave);
- THIS_SCAL( size, ratio, pa, inc);
- }
- t = second() - t;
- if( timing)
- x = t / (double)(2*n_times);
- else
- x = (t > 0) ? (((double)(2*n_times) * (double)(n_flops)*1.e-6) / t) : 0.0;
- printf("%6.4e ", x);
- /* *******************************************************
- ******************************************************* */
- printf("\n");
- free(pa);
- }
- return (0);
- }
-
- int is_random;
-
- void GetArguments( argc, argv)
- int argc;
- char *argv[];
- {
- int i, j, k;
- int nerror = 0;
-
- #define ON 1
-
- max_size = MAX_SIZE;
- min_size = MIN_SIZE;
- inc_size = INC_SIZE;
-
- is_parallel = 0;
- timing = 0;
-
- /* ******************************************************* */
- for ( i = 1 ; (i < argc) && (nerror != ON) ; i ++ ) {
- if( argv[i][0] == '-') {
- switch ( argv[i][1]) {
- case 's' :
- case 'S' :
- is_parallel = 0;
- break;
- case 'p' :
- case 'P' :
- is_parallel = 1;
- break;
- case 't' :
- case 'T' :
- timing = 1;
- break;
- default : nerror = ON;
- }
- }
- else {
- if( i+1 > argc)
- nerror = ON;
- else {
- min_size = atoi( argv[i++]);
- max_size = atoi( argv[i++]);
- inc_size = atoi( argv[i]);
- }
- }
- }
- if( nerror == ON) {
- fprintf( stderr,
- "Usage : %s [-p(arallel)] [n_trials]\n", argv[0]);
- exit(-1);
- }
- }
-